package com.pww.movie.controller;


import com.pww.movie.domain.DTO.UserLikeDTO;
import com.pww.movie.domain.PO.Media;
import com.pww.movie.service.IMediaService;
import com.pww.movie.service.IUserLikeService;
import com.pww.movie.utils.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author pww
 * @since 2025-06-13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user-like")
public class UserLikeController {
    private final IUserLikeService userLikeService;


    /**
     * 用户点赞
     *
     * @param userLikeDTO
     * @return
     */
    @PostMapping("/like")
    public Result like(@RequestBody UserLikeDTO userLikeDTO) {
        Boolean result = userLikeService.like(userLikeDTO);
        return result ? Result.success("点赞成功") : Result.error("点赞失败");
    }

    /**
     * 用户取消点赞
     *
     * @param userLikeDTO
     * @return
     */
    @PostMapping("/Unlike")
    public Result unlike(@RequestBody UserLikeDTO userLikeDTO) {
        Boolean result = userLikeService.unlike(userLikeDTO);
        return result ? Result.success("取消点赞成功") : Result.error("取消点赞失败");
    }

    /**
     * 获取用户点赞的媒体资源
     *
     * @param mediaType 媒体类型
     * @return 用户点赞的媒体资源列表
     */
    @GetMapping("/getUserLikeNew")
    public Result<List<Media>> getUserLike(@RequestParam String mediaType) {
        List<Media> likedMedia = userLikeService.getUserLikedMedia(mediaType);
        return Result.success(likedMedia);
    }
}
